package com.dianrui.qiyouriding.activity;

import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.dianrui.qiyouriding.R;
import com.dianrui.qiyouriding.event.GetPartABitmap;
import com.dianrui.qiyouriding.view.LinePathView;

import org.greenrobot.eventbus.EventBus;

import java.io.IOException;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 请签名
 */
public class WriteSignActivity extends BaseActivity {

    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.linepathview)
    LinePathView linepathview;


    @Override
    public int getContentViewId() {
        return R.layout.activity_write_sign;
    }

    @Override
    public void initView() {
        title.setText("请签名");

    }

    @Override
    public void initData() {

    }


    @OnClick({R.id.back, R.id.reset_path, R.id.save_path})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;

            case R.id.reset_path:
                linepathview.clear();
                linepathview.setBackColor(Color.WHITE);
                linepathview.setPaintWidth(3);
                linepathview.setPenColor(Color.BLACK);
                break;

            case R.id.save_path:
                if (linepathview.getTouched()) {
                    try {
                        linepathview.save("/storage/emulated/qy_agreement.jpg", true, 10);
                        Bitmap bitMap = linepathview.getBitMap();
                        EventBus.getDefault().post(new GetPartABitmap(bitMap));
                        finish();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    Toast.makeText(WriteSignActivity.this, "请您先签名~", Toast.LENGTH_SHORT).show();
                }
                break;

                default:
                    break;
        }
    }
}
